define("gallery/table/0.0.1/table-debug", ["$", "widget", "base", "class", "events", "easing"], function (require, exports, module) {
    var $ = require('$');
    var Widget = require('widget');

    var Table = Widget.extend({
        attrs: {
            triggers: {
                value: '.table',
                getter: function (val) {
                    return $(val);
                }
            },
            column: null,
            row: null,
            checkbox: false,
            border: false
        },
        events: {
            "click [data-role=checkall]": function (e) {
                var $thCheckbox = $(e.target);
                var $tdCheckbox = this.element.find('td .i-checkbox');
                if ($thCheckbox.attr('checked')) {
                    $tdCheckbox.each(function () {
                        $(this).attr('checked', true);
                    });
                } else {
                    $tdCheckbox.each(function () {
                        $(this).attr('checked', false);
                    });
                }
            }
        },
        setup: function () {
            this._initHeader();
            this._initBody();
        },
        _initHeader() {
            var column = this.get('column');
            var checkbox = this.get('checkbox');
            var result = '<table class="i-table">';

            result += '<thead>'
            result += ' <tr>'
            if (checkbox) {
                result += '<th style="width:60px"><input class="i-checkbox" type="checkbox" data-role="checkall" /></th>';
            }
            for (var i = 0, len = column.length; i < len; i++) {
                result += '<th  style="width:' + (column[i].width || 'auto') + '">' + column[i].text + '</th>';
            }
            result += ' </tr>'
            result += '</thead>'
            result += '<tbody class="table-body"></tbody>'
            result += '</table>';

            this.element.html(result);
        },
        _initBody() {
            var row = this.get('row');
            var column = this.get('column');
            var checkbox = this.get('checkbox');
            var result = '';

            for (var i = 0, len = row.length; i < len; i++) {
                result += '<tr>';
                if (checkbox) {
                    result += '<td style="width:60px"><input class="i-checkbox" type="checkbox"/></td>';
                }
                for (var j = 0, clen = column.length; j < clen; j++) {
                    result += '<td  style="width:' + (column[j].width || 'auto') + '">' + row[i][column[j].value] + '</td>';

                }
                result += '</tr>';
            }

            this.element.find('.table-body').html(result);
        }
    });
    module.exports = Table;

});